<?php

/**
 * BuddyPress - Users Header
 *
 * @package BuddyPress
 * @subpackage bp-default
 */

?>

<?php do_action( 'bp_before_member_header' ); ?>

<div id="item-header-avatar">
	<a href="<?php bp_user_link(); ?>">

		<?php bp_displayed_user_avatar( 'type=full' ); ?>

	</a>
</div><!-- #item-header-avatar -->

<div id="item-header-content">
	
	<div class="item-list-tabs no-ajax" id="member-header-subnav" role="navigation">
		<ul>

			<?php 
			/* Display the subnav menu
			 * If a user is displaying their own profile, 
			 * set the $bp->current_component from activity to profile
			*/
			if( bp_is_my_profile() && bp_current_component() == 'activity') {
				global $bp;
				$bp->current_component = 'profile';
				//get_subnav_options();
				bp_get_options_nav();
			}
			 else if( bp_current_component() == 'messages' || bp_current_component() == 'groups' || bp_current_component() == 'settings' )
				bp_get_options_nav();
			?>

		</ul>
	</div><!-- .item-list-tabs -->
	
	<h2>
		<a href="<?php bp_displayed_user_link(); ?>"><?php bp_displayed_user_fullname(); ?></a>
	</h2>

	<span class="user-nicename">@<?php bp_displayed_user_username(); ?></span>
	<span class="activity"><?php bp_last_activity( bp_displayed_user_id() ); ?></span>

	<?php do_action( 'bp_before_member_header_meta' ); ?>

	<div id="item-meta">

		<?php if ( bp_is_active( 'activity' ) ) : ?>

			<div id="latest-update">

				<?php bp_activity_latest_update( bp_displayed_user_id() ); ?>

			</div>

		<?php endif; 
	
		/***
		 * If you'd like to show specific profile fields here use:
		 * bp_profile_field_data( 'field=About Me' ); -- Pass the name of the field
		 * 	<div class="profile_fields" id="age">About Me: <span><?php bp_profile_field_data( 'field=About Me' );?></span></div>
		 */ 
		 do_action( 'bp_profile_header_meta' );
		 ?>
		<div id="member_profile">
			<?php

			//global $bp; //Debug purposes
			//echo "Debug: the current component is '".$bp->current_component."' and the current action is : ".bp_current_action()."\n";  //Debug purposes
			
 			// If viewing any User Activity
			if ( bp_is_current_component( 'activity' ))
				locate_template( array( 'members/single/profile/profile-loop.php' ), true );
			// If viewing the logged in User Profile/Messages/Groups
			if ( bp_is_my_profile() ) {
			
				// User Profile
				if( bp_is_current_component( 'profile') )
					locate_template( array( 'members/single/profile.php'    ), true );
				//Messages
				elseif( bp_is_current_component( 'messages') )
					locate_template( array( 'members/single/messages.php'    ), true );
				// Groups
				elseif ( bp_is_current_component( 'groups') )
					echo "";
					//locate_template( array( 'members/single/groups.php'    ), true );
			} ?>
			
		</div><!-- #member_profile -->
		
		<div id="item-buttons">

			<?php do_action( 'bp_member_header_actions' ); ?>

		</div><!-- #item-buttons -->
	</div><!-- #item-meta -->
</div><!-- #item-header-content -->
<?php do_action( 'bp_after_member_header' ); ?>

<?php do_action( 'template_notices' ); ?>